/*
 * @Author: your name
 * @Date: 2021-12-09 13:53:23
 * @LastEditTime: 2021-12-09 19:44:07
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \12.9work\test_one\index.js
 */
const koa = require('koa')
const Router = require('koa-router')
const timeTigger = require("./middlewares/timeTigger")
const bodyParser = require('koa-bodyparser')
const serve = require('koa-static')
const path = require('path')
const Mock = require('mockjs')
const app = new koa()
const router = new Router()
app.use(bodyParser())
app.use(serve(path.join(__dirname, "./public")))

const {list} = Mock.mock({
    "list|100": [{
        "id": "@id",
        "name": "@cname",
        "title": "@ctitle",
        "address": "@city(true)"
    }]
})
// router.get('/getList', async (ctx, next) => {
//     console.log(ctx.query)
//     ctx.body = '123'
// })

// router.post('/postList', async (ctx, next) => {
//     console.log(ctx.request.body)
//     ctx.body = '我是post'
// })
// router.post('/postList', async (ctx, next) => {
//     console.log(ctx.params)
//     ctx.body = '我是post'
// })

router.post('api/getList', async (ctx, next) => {
    
    const newList = list.slice((pageIndex - 1) * pageSize, pageSize * pageIndex)
    ctx.body = {
        newList,
        total: list.length
    }
})
app.use(timeTigger())
app.use(router.routes())
app.listen(8080, () => {
    console.log('Service started successfully in 8080!!!!')
})